package org.niko.ds.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * The domain object to store the database table information.
 * 
 * @author dzhang
 */

@Entity
@Table(name = "ds_tables")
public class DsTable {

	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private long id;

	@Column(name = "NAME")
	private String name;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "SID")
	private DsSchema schema;

	//fetch = FetchType.EAGER,
	@OneToMany(mappedBy = "table",  cascade = CascadeType.ALL)
	private List<DsColumn> columns = new ArrayList<DsColumn>();

	public List<DsColumn> getColumns() {
		return columns;
	}

	public void setColumns(List<DsColumn> columns) {
		this.columns = columns;
	}

	public DsSchema getSchema() {
		return schema;
	}

	public void setSchema(DsSchema schema) {
		this.schema = schema;
	}

	public String getName() {
		return name;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	// private int version;
	//
	// public int getVersion() {
	// return version;
	// }
	//
	// public void setVersion(int version) {
	// this.version = version;
	// }
}
